package com.atguigu.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @author: 叶子
 * @date: 2022/01/17 20:12
 * 使用FileChannel和方法transferFrom，完成文件的拷贝
 **/
public class NIOFileChannel04 {
    public static void main(String[] args) throws IOException {
//    创建相关流
        FileInputStream fileInputStream = new FileInputStream("d:\\a.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("d:a2.jpg");
//        获取多个流对应的FileChannel
        FileChannel sourceCh = fileInputStream.getChannel();
        FileChannel destCh = fileOutputStream.getChannel();
//        使用transferForm完成拷贝
        destCh.transferFrom(sourceCh,0,sourceCh.size());
//        关闭相关通道和流
        sourceCh.close();
        destCh.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}